package com.srit.recipes.controller;

import com.srit.recipes.common.response.JpaPage;
import com.srit.recipes.common.response.Response;
import com.srit.recipes.entity.ProcurementDetailInfo;
import com.srit.recipes.entity.WeekRecipes;
import com.srit.recipes.service.ProcurementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "采购")
public class ProcurementController {

    @Autowired
    private ProcurementService procurementService;


    @PostMapping("/procurement/create/{id}")
    @ApiOperation(value = "1 生成采购单, 参数是食谱id, 只传审核通过的食谱", notes = "采购单的审核状态加在食谱数据里面")
    public Response createProcurement(@PathVariable int id) {
        return Response.success(procurementService.createProcurement(id));
    }

    @GetMapping("/procurement/detail")
    @ApiOperation("2 查询食谱的采购单, 只用传 recipesId和name, name是模糊查询")
    public Response procurementDetail(ProcurementDetailInfo procurementDetailInfo, JpaPage jpaPage) {
        return Response.success(procurementService.procurementDetail(procurementDetailInfo, jpaPage));
    }


    @DeleteMapping("/procurement/delete/{id}")
    @ApiOperation("3 删除一整个采购单")
    public Response procurementDelete(@PathVariable int id) {
        return Response.success(procurementService.procurementDelete(id));
    }

    @PostMapping("/procurement/detail/update")
    @ApiOperation(value = "4 修改采购单的详细数据， 比如修改采购数量和名称之类的")
    public Response updateProcurement(@RequestBody ProcurementDetailInfo procurementDetailInfo) {
        return Response.success(procurementService.updateProcurement(procurementDetailInfo));
    }

    @DeleteMapping("/procurement/detail/delete/{id}")
    @ApiOperation("5 删除某个采购数据")
    public Response procurementDetailDelete(@PathVariable int id) {
        return Response.success(procurementService.procurementDetailDelete(id));
    }

    @GetMapping("/recipes/procurement/list")
    @ApiOperation(value = "6 查询待审核的采购单")
    public Response recipesProcurementList(JpaPage jpaPage) {
        return Response.success(procurementService.recipesProcurementList(jpaPage));
    }

    @GetMapping("/procurement/examine/submit/{id}")
    @ApiOperation("7 提交采购单审核")
    public Response submitProcurementExamine(@PathVariable int id) {
        return Response.success(procurementService.submitProcurementExamine(id));
    }

    @PostMapping("/procurement/examine/{id}")
    @ApiOperation("8 采购单审核意见，通过或者不通过, 只需要传id， procurementState，proExamineMsg三个字段；state： 0创建中 1: 审核中 2: 审核不通过 3: 审核通过")
    public Response procurementExamine(@RequestBody WeekRecipes weekRecipes) {
        return Response.success(procurementService.procurementExamine(weekRecipes));
    }

    @GetMapping("/procurement/export")
    @ApiOperation("9 导出, 只需要传recipesId和week, week不传则导出所有,传的话导出指定天")
    public Response procurementExport(ProcurementDetailInfo procurementDetailInfo, HttpServletResponse response) throws Exception {
        return Response.success(procurementService.procurementExport(procurementDetailInfo, response));
    }








}
